<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############


class JFX_Module_Blockstyle_Property_Margin extends JFX_Module_Blockstyle_Property_Base
{
	public $id = 'margin';
	public $cssName = 'margin';
	public $title = 'Margin';

	public function init(){

		$marginTop = new JFX_Module_Blockstyle_Widget_Slider($this);
		$marginTop->name = 'Margin Top';
		$marginTop->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PIXEL;
		$marginTop->max = 300;
		$marginTop->min = -50;
		$marginTop->value = 0;
		$marginTop->units[2] = 'auto';
		$marginTop->unitNames[2] = 'Auto';
		$marginTop->cssName = 'margin-top';
		$marginTop->instanceId = $this->instanceId.'-margintop';
		$this->widgets[] = $marginTop;


		$marginRight = new JFX_Module_Blockstyle_Widget_Slider($this);
		$marginRight->name = 'Margin Right';
		$marginRight->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PIXEL;
		$marginRight->max = 300;
		$marginRight->min = -50;
		$marginRight->units[2] = 'auto';
		$marginRight->unitNames[2] = 'Auto';
		$marginRight->value = 0;
		$marginRight->cssName = 'margin-right';
		$marginRight->instanceId = $this->instanceId.'-marginright';
		$this->widgets[] = $marginRight;

		$marginBottom = new JFX_Module_Blockstyle_Widget_Slider($this);
		$marginBottom->name = 'Margin Bottom';
		$marginBottom->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PIXEL;
		$marginBottom->max = 300;
		$marginBottom->min = -50;
		$marginBottom->value = 0;
		$marginBottom->units[2] = 'auto';
		$marginBottom->unitNames[2] = 'Auto';
		$marginBottom->cssName = 'margin-bottom';
		$marginBottom->instanceId = $this->instanceId.'-marginbottom';
		$this->widgets[] = $marginBottom;

		$marginLeft = new JFX_Module_Blockstyle_Widget_Slider($this);
		$marginLeft->name = 'Margin Left';
		$marginLeft->unit = JFX_Module_Blockstyle_Widget_Slider::$UNIT_PIXEL;
		$marginLeft->max = 300;
		$marginLeft->min = -50;
		$marginLeft->value = 0;
		$marginLeft->units[2] = 'auto';
		$marginLeft->unitNames[2] = 'Auto';
		$marginLeft->cssName = 'margin-left';
		$marginLeft->instanceId = $this->instanceId.'-marginleft';
		$this->widgets[] = $marginLeft;


	}


	public function __toCss(){
		$outputString = '';

		if(!$this->hasEnabledWidget()){
			return $outputString;
		}


		if(!$this->hasEnabledWidget() || $this->cssName=='' || $this->cssName != $this->id){
			return '/*not enabled '.$this->cssName.'*/ '.$outputString;
		}

		$marginTopWidget = $this->getWidget($this->instanceId.'-margintop');
		$marginBottomWidget = $this->getWidget($this->instanceId.'-marginbottom');
		$marginRightWidget = $this->getWidget($this->instanceId.'-marginright');
		$marginLeftWidget = $this->getWidget($this->instanceId.'-marginleft');

		if($marginTopWidget->enabled){
			if($marginTopWidget->unit=='auto'){
				$cssValue = 'auto';
			}else{
				$cssValue = $marginTopWidget->value.$marginTopWidget->unit;
			}
			$outputString .= '	margin-top : '.$cssValue.";\n";
		}

		if($marginBottomWidget->enabled){
			if($marginBottomWidget->unit=='auto'){
				$cssValue = 'auto';
			}else{
				$cssValue = $marginBottomWidget->value.$marginBottomWidget->unit;
			}
			$outputString .= '	margin-bottom : '.$cssValue.";\n";
		}

		if($marginLeftWidget->enabled){
			if($marginLeftWidget->unit=='auto'){
				$cssValue = 'auto';
			}else{
				$cssValue = $marginLeftWidget->value.$marginLeftWidget->unit;
			}
			$outputString .= '	margin-left : '.$cssValue.";\n";
		}

		if($marginRightWidget->enabled){
			if($marginRightWidget->unit=='auto'){
				$cssValue = 'auto';
			}else{
				$cssValue = $marginRightWidget->value.$marginRightWidget->unit;
			}
			$outputString .= '	margin-right : '.$cssValue.";\n";
		}

		return $outputString;
	}
}





